package cn.ibdsr.human.util;

import lombok.extern.slf4j.Slf4j;

import org.springframework.util.StringUtils;

/**
 * 字符转义工具类
 * @author chenglx
 * @version V1.0
 * @date 2020/4/14 17:25
 * <p>
 * Date Author Description
 * ------------------------------------------------------
 * 2020/4/14 chenglx init
 */
@Slf4j
public class CharEscapeUtils {

    /**
     * 将输入字符串中的HTML、JavaScript、SQL特殊字符进行转义
     * @param in
     * @return
     */
    public static String escape(String in) {
        log.info("escape(): input: {}", in);
        if (StringUtils.isEmpty(in)) {
            log.info("escape(): empty output");
            return in;
        }
/*
        // HTML特殊字符转义
        String out = HtmlUtils.htmlEscape(in);
        log.info("escape(): after html escape: {}", out);
        // JavaScript特殊字符转义
        out = JavaScriptUtils.javaScriptEscape(out);
        log.info("escape():  after js escape: {}", out);
        // SQL特殊字符转义
        out = StringEscapeUtils.escapeSql(out);
        log.info("escape():  after sql escape: {}", out);
        return out;
*/
        return in;
    }

    public static void main(String[] args) {
        String specialStr = "<div id=\"testDiv\">test1;test2</div>";
        System.out.println(specialStr);
        String str1 = CharEscapeUtils.escape(specialStr);
        System.out.println(str1);


//        specialStr = "";

    }
}
